package com.a3dweijing.wetouch2.adapter;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.a3dweijing.wetouch2.Common.CallBack;
import com.a3dweijing.wetouch2.Common.listview.CommonListviewAdapter;
import com.a3dweijing.wetouch2.Common.listview.ViewHolderListview;
import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.GlideUtil;
import com.a3dweijing.wetouch2.bean.GoodsListBean;
import com.a3dweijing.wetouch2.bean.ShoppingCartItem;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2018/3/28.
 */

public class ShoppingCartAcitivityAdapter extends CommonListviewAdapter
{
    public HashMap<Integer, Boolean> getMap()
    {
        return map;
    }
    
    private CallBack callBack;
    
    private HashMap<Integer, Boolean> map = new HashMap<>();
    
    public ShoppingCartAcitivityAdapter(Context context, List list, int layoutId, CallBack callBack)
    {
        super(context, list, layoutId);
        this.callBack = callBack;
    }
    
    public void resetmap()
    {
        map.clear();
        for (int i = 0; i < list.size(); i++)
        {
            map.put(i, false);
        }
    }
    
    @Override
    public void convert(ViewHolderListview holder, Object o, final int i)
    {
       GoodsListBean o1 = (GoodsListBean)o;
        final CheckBox checkBox = holder.getView(R.id.rb);
        ImageView imageview = holder.getView(R.id.imageview);
        TextView name = holder.getView(R.id.name);
        TextView money = holder.getView(R.id.money);
        TextView num = holder.getView(R.id.num);
        final ImageView add = holder.getView(R.id.add);
        final ImageView jian = holder.getView(R.id.jian);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               callBack.doNext(i,add.getId());
            }
        });
        jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.doNext(i,jian.getId());
            }
        });
        holder.getView(R.id.jian);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b)
            {
                map.put(i, b);
                callBack.doNext(0, null);
            }
        });
        if (map.containsKey(i) && map.get(i))
        {
            checkBox.setChecked(true);
        }
        else
            checkBox.setChecked(false);
        GlideUtil.getInstance().showImage(context, o1.getGoods_img(), imageview);
        name.setText(o1.getGoods_name());
        money.setText("￥：" + o1.getGoods_money() + "");
        num.setText("x" + o1.getGoods_number());
    }
}
